package com.cnlxu.data;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.cninlaxu.curltest.R;

import java.util.ArrayList;

/**
 * Created by cnlxu on 2016/8/9.
 */
public class StickerAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<StickerModel> list;
    class ViewHold {
        public TextView tvWord;
        public TextView tvCounter;
        public TextView tvStatus;
    }

    public StickerAdapter(Context context, ArrayList<StickerModel> data){
        super();
        this.context = context;
        this.list = data;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return list.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHold hold;
        LayoutInflater inflater ;
        if (convertView == null) {
            hold = new ViewHold();
            inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(
                    R.layout.cornerlist_item, null);
            convertView.setTag(hold);
        } else {
            hold = (ViewHold) convertView.getTag();
        }

        hold.tvWord = (TextView)convertView.findViewById(R.id.tv_word);
        hold.tvWord.setText(list.get(position).getWord());
        hold.tvCounter = (TextView) convertView.findViewById(R.id.tv_test_count);
        hold.tvCounter.setText(String.valueOf(list.get(position).getCounter()));
        hold.tvStatus = (TextView)convertView.findViewById(R.id.tv_status);
        int status = list.get(position).getStatus();
        String sStatus;
        if(status ==0) {
            sStatus = "X";
        }
        else{
            sStatus = "V";
        }
        hold.tvStatus.setText(sStatus);
        return convertView;

    }
}
